const formatVoteStates = (comment) => {
  if (!comment.has_vote) return {};
  return {
    like: comment.has_vote.like,
    dislike: comment.has_vote.dis_like,
  };
};

const formatVoteCounts = comment => ({
  like: comment.votes.like_size,
  dislike: comment.votes.dis_like_size,
});

export const formatComment = comment => ({
  id: comment.id,
  content: comment.content,
  subs: comment.children_count,

  author: comment.user, // id nickname avatar
  receiver: comment.receiver, // id nickname avatar 回复的谁

  voteStates: formatVoteStates(comment),
  voteCounts: formatVoteCounts(comment),

  created_at: comment.created_at,
  updated_at: comment.updated_at,
});

export const formatComments = comments => comments.map(i => formatComment(i));
